<script lang="ts" setup>
import { PeaceColumn } from '@/components/type/PeaceColumn'
import { ComponentEnum } from '@/enum/ComponentEnum'
import { NFlex } from 'naive-ui'
import { ifFilterUndefinedRepeatNum } from '@/infrastructure/PeaceDataTable/util/PeaceColumnUtil.ts'
import { ObjectUtil } from '@/util/ObjectUtil'
import { PeaceForm } from '@/components/type/PeaceForm'

const props = withDefaults(
  defineProps<{
    peaceForm: PeaceForm
    index: {
      type: Number,
      required: true
    }
    formModel: {
      type: Record<string, unknown>,
      required: true
    }
  }>(),
  {
    show: false,
  },
)
const formParamObj = computed({
  get:()=> props.formModel,
})
const ifMatcherComponent = computed(()=>{
  return props.peaceForm.componentEnum
    && props.peaceForm.componentEnum === ComponentEnum.DATE
    && ObjectUtil.isNullOrUndefined(props.peaceForm.peaceRender)
})
</script>
<template>
  <template v-if="ifMatcherComponent && ObjectUtil.isNullOrUndefined(props.peaceForm.repeatRender)">
    <n-form-item :label="peaceForm?.title as string" :path="peaceForm?.key">
      <n-date-picker
        v-model:value="formParamObj[peaceForm?.key] as number | [number, number] | null"
        :type="peaceForm?.dateType"
        :placeholder="('请选择' + peaceForm?.title) as string"
      />
    </n-form-item>
  </template>
  <template v-if="ifMatcherComponent && ObjectUtil.isNotNullAndUndefined(props.peaceForm.repeatRender)">
    <n-form-item :label="peaceForm?.title as string">
      <template v-for="(numVal,numIndex) in props.peaceForm?.repeatRender?.num" :key="index + '_' + numIndex">
        <n-flex>
          <n-date-picker
            v-model:value="formParamObj[peaceForm?.repeatRender?.returnFileNames[numIndex]] as number | [number, number] | null"
            :type="peaceForm?.dateType"
            :placeholder="('请选择' + peaceForm?.title) as string"
          />
        </n-flex>
      </template>
    </n-form-item>
  </template>
</template>
<style scoped></style>
